package tests;

import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.Test;

import engine.Logger;
import engine.Project;
import engine.Logger.LogListener;
import engine.Project.ProjectProperty;

public class LoggerTest {

	int num;
	String msg;
	
	
	@Test
	public void testDoesReceiveMessage() {
		num = 0;
		Logger.addLogListener(new LogListener(){

			@Override
			public void handleMessage(String msg) {
				num++;
			}
			
		});
		assertEquals(0, num);
		Logger.log("Hej");
		assertEquals(1, num);
	}
	
	@Test
	public void testCanRemoveSelf() {
		num = 0;
		LogListener ll = new LogListener(){

			@Override
			public void handleMessage(String msg) {
				num++;
			}
			
		};
		Logger.addLogListener(ll);
		
		assertEquals(0, num);
		Logger.log("Hej");
		assertEquals(1, num);
		Logger.removeListener(ll);
		Logger.log("Hej");
		assertEquals(1, num);
		
	}
	
	@Test
	public void testReceivesCorrectMessage() {
		msg = "";
		LogListener ll = new LogListener(){

			@Override
			public void handleMessage(String msg) {
				LoggerTest.this.msg = msg;
			}
			
		};
		Logger.addLogListener(ll);
		
		Logger.log("Hej");
		assertEquals(msg, "Hej");
		Logger.log("Hej igen");
		assertNotSame(msg, "Hej");
	}
	
}
